package com.lancoo.edu.platform.operation.commons.service.api.school;


import com.alibaba.fastjson.TypeReference;
import com.lancoo.edu.platform.operation.commons.domain.api.code.Code2Info;
import com.lancoo.edu.platform.operation.commons.domain.api.school.Holiday;
import com.lancoo.edu.platform.operation.commons.domain.api.school.LegalHoliday;
import com.lancoo.edu.platform.operation.commons.service.api.YunBaseApiService;
import com.lancoo.edu.platform.operation.commons.utils.HttpUtil;

import com.lancoo.edu.platform.operation.commons.utils.JsonFileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 【基础平台】-学期信息【API】业务逻辑
 * @author pky
 */
@Slf4j
@Service
public class TermApiService extends YunBaseApiService {


    /**
     * 获取学校节假日、补班、校园活动日期列表
     * @param schoolId 学校ID，单学校时可不传
     * @param term 学期，默认为当前学期格式：2022-202302
     */
    public Holiday getHolidayList(String schoolId, String term) {
        String url = baseUrl + "/SysMgr/Setting/Holiday/GetHolidayList";
        Map<String, String> paramsMap = getParamsMap();
        paramsMap.put("schoolID", schoolId);
        paramsMap.put("term", term);
        String resultStr = HttpUtil.sendGet(url, paramsMap);
        log.info("获取获取学校节假日列表:" + resultStr);
        return getData2(resultStr, new TypeReference<Code2Info<Holiday>>() {
        });
    }

    /**
     * 接收https://timor.tech/api/holiday/year/2024/ 接口返回的2024年法定节假日
     * @param year 年份
     * @return 2024年法定节假日
     */
    public LegalHoliday getHolidayList(String year) {
        String jsonUrl = "json/schedule/holidays/"+year+"_holidays.json";
        LegalHoliday legalHoliday = JsonFileUtil.getJsonToObject(jsonUrl, LegalHoliday.class);
        return legalHoliday;
    }

}
